/*
 * @lc app=leetcode.cn id=11 lang=java
 *
 * [11] 盛最多水的容器
 */

// @lc code=start
class Solution {

    public int maxArea(int[] height) {
        int max = 0;
        int l=0,r=height.length-1;
        while(l<r){
            max=Integer.max(max, Integer.min(height[l], height[r])*(r-l));
            if(height[l]>height[r]){
                --r;
            }
            else{
                ++l;
            }
        }
        return max;
    }
}
// @lc code=end

/*
    暴力法
    public int maxArea(int[] height) {
        int max = 0;
        for (int i = 0; i < height.length - 1; i++) {
            for (int j = i + 1; j < height.length; j++) {
                max = Integer.max(max, (j - i) * Integer.min(height[i], height[j]));
            }
        }
        return max;
    }

    改善后的暴力法（时间减少约一半）
    public int maxArea(int[] height) {
        int max = 0;
        int maxih = -1;
        
        for (int i = 0; i < height.length - 1; i++) {
            if(maxih<height[i]) maxih =height[i];
            else continue;
            for (int j = i + 1; j < height.length; j++) {
                max = Integer.max(max,(j - i) * Integer.min(height[i], height[j]));
            }
        }
        return max;
    }

    最优的双指针法：
    public int maxArea(int[] height) {
        int max = 0;
        int l=0,r=height.length-1;
        while(l<r){
            max=Integer.max(max, Integer.min(height[l], height[r])*(r-l));
            if(height[l]>height[r]){
                --r;
            }
            else{
                ++l;
            }
        }
        return max;
    }


 */
